import java.io.File;
import java.util.List;

import com.adc.quicktools.constants.ConstantDefine;
import com.adc.quicktools.net.UpOrDownControl;
import com.adc.quicktools.net.ftp.FtpUtil;
import com.adc.quicktools.net.smb.SMBUtil;

/**********************************************************************************
 * Copyright (c) 2012 - 2012,  quick_tools, All right reserved
 * Title:   TestFtp.java 
 * @author shen  shenqiao2012@163.com 
 *  2012-7-18 下午5:30:04 
 *********************************************************************************/

public class TestNetPackage {
	
	public static void testFTPDownload() {
		String remotePath="/D:/home/cipas/DCM/product/DSTR/FF/PMON/2009/*1.PNG";
		String matchedName=new File(remotePath).getName();
		String remoteParentPath=remotePath.substring(0, remotePath.lastIndexOf("/"));
		String localFilePath="E:/TempTest/temp/test/CMDP_CMD_DSTR_DCM_FF_AGLB_L3H7H_PB_20090800000000_PMON_1.PNG";
		boolean b=false;
		List<String> resList=FtpUtil.downloadMultFileByFTP(FtpUtil.registFtpServerInfo("10.22.0.116", 21, "dcm", "dcm123", "/home/cipas/DCM/"), remoteParentPath,matchedName, new File(localFilePath).getParent());
		System.out.println(resList.size());
	}
	
	public static void testFTPupload() {
		String localFilePath="E:/TempTest/temp/test/CMDP_CMD_DSTR_DCM_FF_AGLB_L3H7H_PB_20090800000000_PMON_1.PNG";
		String remoteFilePath="/home/quanjing/product/test01/test02/CMDP_CMD_DSTR_DCM_FF_AGLB_L3H7H_PB_20090800000000_PMON_1.PNG";
		boolean b=FtpUtil.uploadOneFileByFTP(FtpUtil.registFtpServerInfo("10.10.31.160", 21, "quanjing", "quanjing", "/home/quanjing/product/"), remoteFilePath, localFilePath);
		System.out.println(b);
	}
	
	public static void testFtpDelete() {
		String remoteFilePath="/home/quanjing/product/test01";
//		String remoteFilePath="/home/quanjing/product/test01/test02/CMDP_CMD_DSTR_DCM_FF_AGLB_L3H7H_PB_20090800000000_PMON_1.PNG";
		boolean b=FtpUtil.deleteByFtp(FtpUtil.registFtpServerInfo("10.10.31.160", 21, "quanjing", "quanjing", "/home/quanjing/product/"), remoteFilePath);
		System.out.println(b);
	}
	
	public static void testFtpCreateDir() {
		String remoteFilePath="/home/quanjing/product/test01/test2/test.z/1.txt";
//		FtpUtil.ensureParentPathByFTP(FtpUtil.registFtpServerInfo("10.10.31.160", 21, "quanjing", "quanjing", "/home/quanjing/product/"), remoteFilePath);
		boolean b=FtpUtil.makeDirectoryByFTP(FtpUtil.registFtpServerInfo("10.10.31.160", 21, "quanjing", "quanjing", "/home/quanjing/product/"), remoteFilePath);
		System.err.println(b);
	}
	
	public static void testFtpRename() {
		String newFilePath="/home/quanjing/product/test01/rename.test/newfile/newFile.PNG";
		String oldFilePath="/home/quanjing/product/test01/test02/CMDP_CMD_DSTR_DCM_FF_AGLB_L3H7H_PB_20090800000000_PMON_1.PNG";
		boolean b=FtpUtil.renameByFtp(FtpUtil.registFtpServerInfo("10.10.31.160", 21, "quanjing", "quanjing", "/home/quanjing/product/"), oldFilePath,newFilePath);
		System.err.println(b);
	}
	
	public static void testSMBDownload() {
		String localFile="E:/TempTest/testSMB/test_test_standard_filename.txt";
		String localDir="E:/TempTest/testSMB";
		String remoteFile="smb://ncc:ncc@10.10.31.19/ncc/testsmb/testroot/cipasm12-12.cps";
		String remoteDir="smb://ncc:ncc@10.10.31.19/ncc/testsmb/testroot";
		List<String> localList1=SMBUtil.downloadBySMB(remoteFile, localFile, true);
//		List<String> localList2=SMBUtil.downloadBySMB(remoteDir, localDir, false);
		System.out.println("Result is \n\t[localList1:"+localList1.size()+"] ");
//		System.out.println("\t[localList2:"+localList2.size()+"]");
	}
	
	public static void testSMBUpload() {
		String localFile="E:/TempTest/testSMB/test_test_standard_filename.txt";
		String localDir="E:/TempTest/testSMB";
		String remoteFile="smb://ncc:ncc@10.10.31.19/ncc/testmkdir/test002/cipasm12-12.cps";
		String remoteDir="smb://ncc:ncc@10.10.31.19/ncc/test123/test003";
//		List<String> remoteList1=SMBUtil.uploadBySMB(remoteFile,localFile, true);
//		System.out.println("Result is \n\t[remoteList1:"+remoteList1.size()+"] ");
		List<String> remoteList2=SMBUtil.uploadBySMB(remoteDir,localDir, false);
		System.out.println("Result is \n\t[remoteList2:"+remoteList2.size()+"] ");
	}
	
	public static void testSMBDelete() {
//		String remoteUrl="smb://ncc:ncc@10.10.31.19/ncc/testmkdir/";
		String remoteUrl="smb://ncc:ncc@10.10.31.19/ncc/test000";
//		String remoteUrl="smb://ncc:ncc@10.10.31.19/ncc/testsmb/";
		boolean b=SMBUtil.deleteBySMB(remoteUrl);
		System.err.println("Test Delete result is ["+b+"]");
	}
	
	public static void testSMBRename() {
		String remotePath="smb://ncc:ncc@10.10.31.19/ncc/testsmb/testroot/cipasm12-12.cps";
		String destPathString="smb://ncc:ncc@10.10.31.19/ncc/testsmb/testroot/test_test_standard_filename.txt";
		String destPathString1="smb://ncc:ncc@10.10.31.19/ncc/test000/testroot/test_test_standard_filename.txt";
//		boolean b=SMBUtil.renameBySMB(remotePath, destPathString);
		boolean b1=SMBUtil.renameAndMoveBySMB(remotePath, destPathString1);
//		System.out.println("Finally Result is ["+b+","+b1+"]");
	}
	
	public static void testSMBCopyTo() {
		String remotePath="smb://ncc:ncc@10.10.31.19/ncc/testsmb/testroot/cipasm12-12.cps";
		String remoteParentPath="smb://ncc:ncc@10.10.31.19/ncc/testsmb/";
		String destPath="smb://ncc:ncc@10.10.31.19/ncc/testsmb2/testroot/test_stand.cps";
		String destParentPath="smb://ncc:ncc@10.10.31.19/ncc/testcopy";
//		boolean b1=SMBUtil.copyToBySMB(remotePath, destPath);
//		System.out.println("copy result:[b1="+b1+"]");
		boolean b2 = SMBUtil.copyToBySMB(remoteParentPath, destParentPath);
		System.out.println("copy result:[b2="+b2+"]");
	}
	
	public static void testUpordownThread() {
		String remotePath="/raw/file_library/DCM/testdir/test123/2012/ersrt/CMDP_CMD_DSTR_DCM_PRE_ACHN_L88_PB_20120000000000_YEAR_1.PNG";
		String localPath="E:/TempTest/temp/CMDP_CMD_DSTR_DCM_PRE_ACHN_L88_PB_20120000000000_YEAR_1.PNG";
		UpOrDownControl uControl=new UpOrDownControl();
		int rv=uControl.upOrDownByType(ConstantDefine.FTP_UP, 
				FtpUtil.registFtpServerInfo("10.10.31.19", 21, "nmic", 
						"nmic", "/raw/file_library/DCM/"), 
						remotePath, localPath);
		System.out.println("Return Value is ["+rv+"]");
	}
	
	public static void main(String[] args) {
//		testFtpCreateDir();
//		testFTPupload();
//		testFtpDelete();
//		testFtpRename();
//		testSMBDownload();
//		testSMBUpload();
//		testSMBDelete();
//		testSMBRename();
//		testSMBCopyTo();
		testUpordownThread();
	}

}
